package com.itheima.d3_thread_safe;

/**
 * 目标：模拟线程安全问题。
 */
public class ThreadTest {
    public static void main(String[] args) {
        TheadPiao theadPiao = new TheadPiao();
        Thread t1 = new Thread(theadPiao, "窗口1");
        Thread t2 = new Thread(theadPiao, "窗口2");
        Thread t3 = new Thread(theadPiao, "窗口3");
        t1.start();
        t2.start();
        t3.start();
    }
}

class TheadPiao implements Runnable {
    private int count = 100;

    @Override
    public void run() {
        while (true) {
            if (count <= 0) {
                break;
            } else {
                count--;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + " 窗口，正在卖票 还剩 " + count + " 张票");
            }
        }
    }
}
